-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(logger): change logging to use stdout #748
Conversation
409dc32
to
ea2c672
Compare
e2e test results here (passing) https://github.com/awslabs/aws-lambda-powertools-typescript/actions/runs/2162686619 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for cleaning up those small things.
I have one question just to double check.
|
||
describe('Middy middleware', () => { | ||
|
||
const ENVIRONMENT_VARIABLES = process.env; | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
jest.spyOn(console, 'log').mockImplementation(() => {}); | ||
jest.spyOn(process.stdout, 'write').mockImplementation(() => null as unknown as boolean); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why double cast? Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's only to please the TypeScript compiler.
If doing null as boolean
it would give me this error:
error TS2352: Conversion of type 'null' to type 'boolean' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
jest.spyOn(process.stdout, 'write').mockImplementation(() => null as boolean);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I'm curious does this change break tracing in cloudwatch? I thought that the default console log formatting is used to correlate logs across requests in cloudwatch tracing and x-ray. |
Hi @mrerichoffman, thanks for the message. I think I have an idea of what you're referring to but I'd like to make sure we are on the same page. Would you mind please opening and elaborating on what you're (not) seeing and what you're expecting to see and where? This would also help others find the same issue in the future since this is an old PR. Thank you! |
Description of your changes
As reported by user @olanb7 on the community Slack and in #747 before this PR Logger would output logs like this:
These logs, although containing a structured JSON, are not JSON as they are always prefixed by
2022-04-08T10:58:44.811Z b6511ee9-4873-404e-b60c-a23cb45d3ff2 INFO
.This also confirmed by a line in the Lambda docs (emphasis mine):
This behaviour works well with CloudWatch but the presence of these prefixes was an issue for customers wanting to use these structured logs elsewhere (both 3rd party services and AWS Managed Grafana).
From this PR onwards Logger will be using its own internal and private version of the
Console
class that only outputs the structured JSON log without any prefix:Aside from 3-lines change in the Logger class, all the rest of the changes in this PR are related to the unit and integration tests.
How to verify this change
See the results of checks inside this PR and e2e tests (to be run).
Also see screenshot below:
Related issues, RFCs
#747
PR status
Is this ready for review?: YES
Is it a breaking change?: NO
Checklist
Breaking change checklist
N/A
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.